<CFQUERY NAME="getclient" DATASOURCE="#dsn#">
select *
from tblcustomers
where CustomerNum = <cfqueryparam cfsqltype="cf_sql_integer" value="#accountnumber#">

</CFQUERY>
<cfoutput>

<cfif isdefined("session.ReceiptNum")>



<cflocation url="addtocart.cfm?ProdID=#form.ProdID#&qty=#form.qty#">

<cfelse>


<cfset today = now()>
<cfset mytime = timeformat(now(), "hh:mm:ss tt")>



<cflock timeout=20 scope="Session" type="Exclusive">

<cfset structdelete(SESSION, "ReceiptNum")>
</cflock>

<CFQUERY NAME="getcounter" DATASOURCE="#dsn#">
select *
from tblcounter
where id = 1
</CFQUERY>


<cfset newReceiptNum = #getcounter.Counter# + 1>



<cfset mytime = timeformat(now(), "hh:mm:ss tt")>

<!---<CFSET MYPRICE = #form.Price# * #QTY#>--->
<CFQUERY NAME="checkrenum" DATASOURCE="#dsn#">
select * 
from tblorders
where ReceiptNum = #newReceiptNum#
</CFQUERY>



<cflock timeout=20 scope="Session" type="Exclusive">

<cfset session.ReceiptNum = "#newReceiptNum#">
</cflock>

<cfquery datasource="#dsn#">
UPDATE tblcounter
SET Counter = #newReceiptNum#
where id = 1 
</cfquery>

<cfquery name="startorder" datasource="#dsn#">
INSERT INTO tblorders ( ReceiptNum, CustomerNum, TransDate, TransTime, Terminal, Location, Pin)
VALUES(
<cfqueryparam cfsqltype="cf_sql_integer" value="#session.ReceiptNum#">,
<cfqueryparam cfsqltype="cf_sql_integer" value="#accountnumber#">,
<cfqueryparam cfsqltype="cf_sql_timestamp" value="#today#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#mytime#">,
<cfif isdefined("session.Terminal")>#session.Terminal#<cfelse>'1'</cfif>,
<cfif not isdefined("session.Location")>''<cfelse>'#session.Location#'</cfif>,
<Cfif not isdefined("session.Pin")>null<cfelse>#session.Pin#</Cfif>

)
</cfquery>





<CFQUERY DATASOURCE="#dsn#">
INSERT INTO tbltranslog (Code, ReceiptNum, TransDate, TransTime, username)
VALUES (
'C',
#session.ReceiptNum#,
<cfqueryparam cfsqltype="cf_sql_date" value="#today#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#mytime#">,
'#session.username#'
)
</CFQUERY>

<cfif isdefined("form.ProdID")>
<cflocation url="addtocart.cfm?ProdID=#form.ProdID#&new=1&qty=#form.qty#">
<cfelse>


</cfif>
</cfif>



</cfoutput>